﻿
Partial Class Apps_report_log_menu_system
    Inherits System.Web.UI.Page

    Shared isStartDateSelected As Boolean
    Shared isEndDateSelected As Boolean

    Protected Sub btnFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFilter.Click

        Try
            Dim startDate As Date
            Dim endDate As Date

            'If Not isStartDateSelected Then
            '    GenericHelper.ShowAlert(Me, "กรุณาเลือกวันที่")
            'ElseIf Not isEndDateSelected Then
            '    GenericHelper.ShowAlert(Me, "กรุณาเลือกวันที่")
            'Else

            startDate = calendarStart.SelectedDate.ToString("yyyy/MM/dd")
            endDate = calendarEnd.SelectedDate.ToString("yyyy/MM/dd")



            If startDate > endDate Then
                GenericHelper.ShowAlert(Me, "กรุณาระบุวันที่ให้ถูกต้อง")
            Else
                Dim url = "../Reports/report_log_system2.aspx?type=1&"

                url &= String.Format("department_code={0}&log_menu={1}&log_type={2}&start_date={3}&end_date={4}&filterType={5}&staff_firstname={6}&staff_lastname={7}&staff_no={8}&str_log_menu={9}&str_staff={10}&str_log_type={11}&", _
                                     0, _
                                     ddlLogMenu.SelectedValue, _
                                     ddlLogType.SelectedValue, _
                                     calendarStart.SelectedDate.ToString("yyyy/MM/dd"), _
                                     calendarEnd.SelectedDate.ToString("yyyy/MM/dd"), _
                                     ddlFilterType.SelectedValue, _
                                     txtKeyword.Text, _
                                     txtKeyword.Text, _
                                     txtKeyword.Text, _
                                     HttpUtility.UrlEncode(ddlLogMenu.SelectedItem.Text), _
                                     HttpUtility.UrlEncode(txtKeyword.Text), _
                                     HttpUtility.UrlEncode(ddlLogType.SelectedItem.Text))

                Dim script = String.Format(" window.open('{0}','_blank'); ", url)

                ScriptManager.RegisterStartupScript( _
                Me, _
                Me.GetType(), _
                Guid.NewGuid().ToString(), _
               script, _
                True _
                )
            End If
            'End If

        Catch ex As Exception
            GenericHelper.ShowAlert(Me, ex.Message)
        End Try

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            isStartDateSelected = False
            isEndDateSelected = False

            lblStartDate.Text = Date.Now().ToString("yyyy/MM/dd")
            lblEndDate.Text = Date.Now().ToString("yyyy/MM/dd")

            calendarStart.SelectedDate = Date.Now()
            calendarEnd.SelectedDate = Date.Now()

        End If
    End Sub

    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        Dim BreadCrumpBG As HtmlControl = Page.Master.FindControl("tdBreadCrump")
        Dim BreadCrump As Literal = Page.Master.FindControl("ltrBreadCrump")
        CodeMatrix.Business.GenericData.SetBreadCrump(BreadCrumpBG, BreadCrump, 45)
    End Sub

    Protected Sub btnStartDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStartDate.Click
        calendarStart.Visible = True
    End Sub

    Protected Sub btnEndDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEndDate.Click
        calendarEnd.Visible = True
    End Sub

    Protected Sub calendarStart_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles calendarStart.SelectionChanged

        ' display the selected date
        lblStartDate.Text = calendarStart.SelectedDate.ToString("yyyy/MM/dd")
        isStartDateSelected = True

        calendarStart.Visible = False

    End Sub

    Protected Sub calendarEnd_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles calendarEnd.SelectionChanged

        ' display the selected date
        lblEndDate.Text = calendarEnd.SelectedDate.ToString("yyyy/MM/dd")
        isEndDateSelected = True

        calendarEnd.Visible = False

    End Sub
End Class
